﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SPA.Serveices
{
    public partial class Server : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string tag = Request["action"] ?? string.Empty;
            if (tag.ToLower() == "getpersonlist")
            {
                string res = "[";
                for (int i = 1; i < 11; i++)
                {
                    res += "{";
                    res += "id:'" + i + "',name:'name_" + i + "',birthday:'birthday_" + i + "',address:'address_:" + i + "'";
                    res += "},";
                }
                res = res.Substring(0, res.LastIndexOf(','));
                res += "]";

                Response.Write(res);
            }
            if (tag.ToLower() == "getbooklist")
            {
                string res = "[";
                for (int i = 1; i < 11; i++)
                {
                    res += "{";
                    res += "id:'" + i + "',name:'book_" + i + "',money:'money_" + i + "'";
                    res += "},";
                }
                res = res.Substring(0, res.LastIndexOf(','));
                res += "]";

                Response.Write(res);
            }
            if (tag == "AddPerson")
            {
                string res = "[";
                for (int i = 1; i < 11; i++)
                {
                    res += "{";
                    res += "id:'" + i + "',name:'name_" + i + "',birthday:'birthday_" + i + "',address:'address_:" + i + "'";
                    res += "},";
                }
                res += "{id:'" + Request["id"] + "',name:'" + Request["name"] + "',birthday:'" + Request["birthday"] + "',address:'" + Request["address"] + "'}";
                res += "]";
                Response.Write(res);
            }
            if (tag == "EditPerson")
            {
                string res = "[";
                for (int i = 1; i < 11; i++)
                {
                    res += "{";
                    res += "id:'" + i + "',name:'name_" + i + "',birthday:'birthday_" + i + "',address:'address_:" + i + "'";
                    res += "},";
                }
                res += "{id:'" + Request["id"] + "',name:'" + Request["name"] + "',birthday:'" + Request["birthday"] + "',address:'" + Request["address"] + "'}";
                res += "]";
                Response.Write(res);
            }
            if (tag == "DeletePerson")
            {
                string res = "[";
                for (int i = 1; i < 11; i++)
                {
                    res += "{";
                    res += "id:'" + i + "',name:'name_" + i + "',birthday:'birthday_" + i + "',address:'address_:" + i + "'";
                    res += "},";
                }
                res += "{id:'" + Request["id"] + "',name:'del',birthday:'del',address:'del'}";
                res += "]";
                Response.Write(res);
            }
            if (tag == "DetailPerson")
            {
                string id = Request["id"] ?? string.Empty;
                string str = "{id:'" + id + "',name:'name_" + id + "',birthday:'birthday_" + id + "',address:'address_" + id + "'}";
                string books = "[";
                for (int i = 1; i < 11; i++)
                {
                    books += "{";
                    books += "id:'" + i + "',name:'book_" + i + "',money:'money_" + i + "'";
                    books += "},";
                }
                books = books.Substring(0, books.LastIndexOf(','));
                books += "]";
                string res = "{person:" + str + ",books:" + books + "}";
                Response.Write(res);
            }
            if (tag == "GetPersonById")
            {
                string id = Request["id"] ?? string.Empty;
                string str = "{id:'" + id + "',name:'name_" + id + "',birthday:'birthday_" + id + "',address:'address_" + id + "'}";
                Response.Write(str);
            }
        }
    }
}